{include file="pageheader_erp.htm"}

{insert_scripts files="../js/jquery.1.3.2.js"}

<style type="text/css">
	.current_page_style
	{
		color:red;
		font-weight:bold;
	}
</style>

 <!-- start supplier group list -->
 <div class="list-div" id="listDiv">
<table  cellpadding="3" cellspacing="1">
  <tr>
    <th width="5%">{$lang.erp_id}</th>
    <th>{$lang.erp_supplier_group_name}</th>
 	<th width="20%">{$lang.erp_admin}</th>
	<th width="8%">{$lang.erp_is_valid}</th>
	<th width="8%">{$lang.erp_operation}</th>
  <tr>
  {foreach from=$supplier_groups item=group}
  <tr id="tr_{$group.group_id}">
    <td align="center">{$group.group_id}</td>
	<td align="center">
		<span style="cursor:pointer;" id="span_group_id_{$group.group_id}">{$group.group_name}</span>
	</td>
	<td>
		<span style="cursor:pointer;"  id="span_admin_{$group.group_id}">{$group.admin_name}</span>
		{if $admins}
		<select id="select_admin_name_{$group.group_id}" style="display:none;">
			{foreach from=$admins item=admin}
				<option value='{$admin.user_id}' {if $group.admin_id eq $admin.user_id}selected='selected'{/if}>{$admin.user_name}</option>
			{/foreach}
		</select>
		{/if}
	</td>

	<td align="center" >
		<span id="is_valid_{$group.group_id}" style="cursor:pointer; color:{if $group.is_valid eq 1}red;{else}black;{/if}">
				{if $group.is_valid eq 1}{$lang.erp_yes}{else}{$lang.erp_no}{/if}
		</span>
	</td>
	<td align="center"  >
		<span id="edit_{$group.group_id}" style="cursor:pointer;">{$lang.erp_operation_edit}</span>
		<span id="delete_{$group.group_id}" style="cursor:pointer;">{$lang.erp_operation_delete}</span>
    </td>				
  </tr>
  {foreachelse}
  <tr><td class="no-records" colspan="5">{$lang.no_records}</td></tr>
  {/foreach}
   <tr><td colspan="5" align="right">{$page}</td></tr>   
</table>
</div>
<!-- end supplier group list -->

{literal}
<script language="JavaScript">
   $(document).ready(function(){
	
   		$("span[id^='is_valid_']").click(function(){
			var group_id=$(this).attr('id');
			
			group_id=group_id.substr('is_valid_'.length,group_id.length-'is_valid_'.length);
			
			function changeIsValidResponse(res)
			{
				if(res.error==0 && res.is_valid==1)
				{
					$("#is_valid_"+group_id).css('color','red');
					$("#is_valid_"+group_id).text('{$lang.erp_yes}');
				}
				else if(res.error==0 && res.is_valid===0)
				{
					$("#is_valid_"+group_id).css('color','black');
					$("#is_valid_"+group_id).text('{$lang.erp_no}');
				}
				else{
					alert(res.message);
				}
			}
			
			Ajax.call('erp_supplier_group.php?act=change_is_valid', 'group_id=' + group_id, changeIsValidResponse, 'POST', 'JSON');
		});


		$("span[id^='span_admin_']").mouseover(function(){
			$(this).css('color','red');
		});
		
		$("span[id^='span_admin_']").mouseout(function(){
			$(this).css('color','black');
		});	
	
		$("span[id^='span_admin_']").click(function(){
			var group_id=$(this).attr('id');
			group_id=group_id.substr('span_admin_'.length,group_id.length-'span_admin_'.length);	
			$(this).hide();
			$("#select_admin_name_"+group_id).show();
		});
		
		$("select[id^='select_admin_name_']").change(function(){
			var group_id=$(this).attr('id');
			group_id=group_id.substr('select_admin_name_'.length,group_id.length-'select_admin_name_'.length);	
			
			var admin_id=$(this).attr('value');
			
			Ajax.call('erp_supplier_group.php?act=change_group_admin', 'group_id=' + group_id+ '&admin_id=' + admin_id, changeSupplierGroupAdminResponse, 'POST', 'JSON');
		
			function changeSupplierGroupAdminResponse(res)
			{
				if(res.error!=0)
				{
					alert(res.message);
				}
				else{
					window.location='{$url}';
				}
			}
		});		

		$("span[id^='delete_']").mouseover(function(){
			$(this).css('color','red');
		});
		
		$("span[id^='delete_']").mouseout(function(){
			$(this).css('color','black');
		});	
		
		$("span[id^='delete_']").click(function(){
			
			var group_id=$(this).attr('id');
			group_id=group_id.substr('delete_'.length,group_id.length-'delete_'.length);	
			
			if(confirm('{$lang.erp_supplier_group_sure_to_delete}'))
			{
				Ajax.call('erp_supplier_group.php?act=delete_supplier_group', 'group_id=' + group_id, deleteSupplierGroup, 'POST', 'JSON');	
			}

			function deleteSupplierGroup(res)
			{
				if(res.error!=0)
				{
					alert(res.message);
				}
				else{
					window.location='{$url}';
				}
			}			
		});		

		$("span[id^='edit_']").mouseover(function(){
			$(this).css('color','red');
		});
		
		$("span[id^='edit_']").mouseout(function(){
			$(this).css('color','black');
		});	
		
		$("span[id^='edit_']").click(function(){
			
			var group_id=$(this).attr('id');
			group_id=group_id.substr('edit_'.length,group_id.length-'edit_'.length);	
			
			window.location='erp_supplier_group.php?act=edit_supplier_group&group_id='+group_id;			
		});	

		$("span[id^='span_group_id_']").mouseover(function(){
			$(this).css('color','red');
		});
		
		$("span[id^='span_group_id_']").mouseout(function(){
			$(this).css('color','black');
		});			
		
		$("span[id^='span_group_id_']").click(function(){
			var group_id=$(this).attr('id');
			group_id=group_id.substr('span_group_id_'.length,group_id.length-'span_group_id_'.length);
			
			window.location='erp_supplier.php?act=list&s_g_id='+group_id;				
		});		
		
   });   
</script>
{/literal}
{include file="pagefooter.htm"}

